﻿namespace DimensionsHelper.Client.WinUi.Helpers;

internal class MessageTypeColorHelper
{
    public static readonly DependencyProperty MessageTypeProperty = DependencyProperty.RegisterAttached(
        "MessageType",
        typeof(MessageType),
        typeof(MessageTypeColorHelper),
        new PropertyMetadata(MessageType.Information, OnMessageTypePropertyChanged));

    private static SolidColorBrush WarningBrush => new(Colors.Orange);

    private static SolidColorBrush ErrorBrush => new(Colors.Red);


    public static MessageType GetMessageType(DependencyObject d) => (MessageType)d.GetValue(MessageTypeProperty);


    public static void SetMessageType(DependencyObject d, MessageType value) => d.SetValue(MessageTypeProperty, value);


    private static void OnMessageTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is not TextBlock control)
        {
            return;
        }

        MessageType type = (MessageType)e.NewValue;
        if (type == MessageType.Warning)
        {
            control.Foreground = WarningBrush;
        }
        else if (type == MessageType.Error)
        {
            control.Foreground = ErrorBrush;
        }
    }
}